package cn.example.web.db.bean;

import lombok.experimental.Accessors;
import lombok.Data;
import lombok.AccessLevel;
import lombok.Setter;
import java.util.Date;
import org.artifact.core.db.BaseBean;
import org.artifact.core.lang.IServer;
import java.util.Map;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.map.MapUtil;
import java.util.HashMap;
@Data
@Accessors(chain = true)
@SuppressWarnings({"rawtypes","unchecked"})
/** 渠道包 */
public abstract class ChannelApp implements BaseBean<ChannelApp> {
	/** 主键 */
	private long id;
	/** 渠道ID */
	private long channelId;
	/** 渠道包名称 */
	private String name;
	/** 创建时间 */
	@Setter(value = AccessLevel.PROTECTED)
	private java.util.Date createDate;
	/** 修改时间 */
	@Setter(value = AccessLevel.PROTECTED)
	private java.util.Date modifiedDate;
	
	


	


	@Override
	public ChannelApp deepCopy() {
		ChannelApp channelApp = null;
		try {
			channelApp = (ChannelApp) super.clone();
			channelApp.createDate = (java.util.Date)this.createDate.clone();
			channelApp.modifiedDate = (java.util.Date)this.modifiedDate.clone();
		} catch (CloneNotSupportedException e) {
			e.printStackTrace();
		}
		onCopy(channelApp);
		return channelApp;
	}

	public <T extends ChannelApp> T build(ChannelApp t){
	    if(t == null) return null;
	    BeanUtil.copyProperties(t, this);
        onRead();
        return (T)this;
	}

	public ChannelApp toSave() {
        if(this.id == 0)
            this.id = (long)IServer.me().getContext().getIdFactory().getId();
		Date now = new Date();
		if (createDate==null) {
			createDate = now;
			modifiedDate = now;
		}else {
			modifiedDate = now;
		}
		onWrite();
		return deepCopy();
	}
	


    /**
     * 写数据
     */
    public Object write(){
        Object[] values = new Object[5];
        values[0] = this.id;
        values[1] = this.channelId;
        values[2] = this.name;
        values[3] = this.createDate;
        values[4] = this.modifiedDate;
        return values;
    }

    /**
     * 读数据
     */
    public ChannelApp read(Object object){
        Object[] array = (Object[])object;
        this.id = (long)array[0];
        this.channelId = (long)array[1];
        this.name = (String)array[2];
        this.createDate = (java.util.Date)array[3];
        this.modifiedDate = (java.util.Date)array[4];
        return this;
    }
    /**
     * 克隆之后
     */
    protected void onCopy(ChannelApp channelApp){

    }

    /**
     * 写数据之前
     */
    protected void onWrite(){
    }

    /**
     * 读数据之后
     */
    protected void onRead(){
    }

	@Override
	public Object pk() {
		return this.id;
	}
}